﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.Common;
/// <summary>
/// Summary description for Rating
/// </summary>
public class Rating
{
    protected static string ProductID;

	public Rating()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public static string GetProductID()
    {
        return ProductID;
    }

    public static void SetProductID(string ProdID)
    {
        ProductID = ProdID;
    }

    // Create a new rating
    public static bool CreateRating(string ProdID, string CustomerName, string Rating, string Comment)
    {
        // get a configured DbCommand object
        DbCommand comm = GenericDataAccess.CreateCommand();
        // set the stored procedure name
        comm.CommandText = "CatalogCreateRating";
        // create a new parameter
        DbParameter param = comm.CreateParameter();
        param.ParameterName = "@ProdID";
        param.Value = ProdID;
        param.DbType = DbType.Int32;
        comm.Parameters.Add(param);
        // create a new parameter
        param = comm.CreateParameter();
        param.ParameterName = "@CustomerName";
        param.Value = CustomerName;
        param.DbType = DbType.String;
        param.Size = 50;
        comm.Parameters.Add(param);
        // create a new parameter
        param = comm.CreateParameter();
        param.ParameterName = "@Rating";
        param.Value = Rating;
        param.DbType = DbType.Int32;
        comm.Parameters.Add(param);
        // create a new parameter
        param = comm.CreateParameter();
        param.ParameterName = "@Comment";
        param.Value = Comment;
        param.DbType = DbType.String;
        param.Size = 4000;
        comm.Parameters.Add(param);
       
        // result will represent the number of changed rows
        int result = -1;
        try
        {
            // execute the stored procedure
            result = GenericDataAccess.ExecuteNonQuery(comm);
        }
        catch
        {
            // any errors are logged in GenericDataAccess, we ingore them here

        }
        // result will be 1 in case of success 
        return (result >= 1);
    }

}